<template>
    <div class="app-container">
        <!-- 查询条件表单 -->
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
            <el-form-item label="品号" prop="itemCode">
                <el-input v-model="queryParams.itemCode" placeholder="请输入品号" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="批号" prop="lotCode">
                <el-input v-model="queryParams.lotCode" placeholder="请输入批号" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="供应商简称" prop="supplierName">
                <el-input v-model="queryParams.supplierName" placeholder="供应商简称" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="单据日期" prop="docDate">
                <el-date-picker v-model="queryParams.docDate" type="date" placeholder="单据日期" format="yyyy年MM月dd日"
                    value-format="yyyy-MM-dd" @keyup.enter.native="handleQuery">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>


        <!-- 表格上方工具栏 -->
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-printer" size="mini" @click="handleBatchPrint"
                    v-hasPermi="['system:index:print']">批量打印</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getMaterielThreeList"></right-toolbar>
        </el-row>

        <!-- 表格 -->
        <el-table v-loading="loading" :data="tableData" @selection-change="handleSelectionChange" height="600" @sort-change="handleSortChange">
            <el-table-column type="selection" width="50" fixed="left" />
            <el-table-column label="单据日期" prop="docDate" width="100" fixed="left" />
            <el-table-column label="单号" prop="docNo" width="150" fixed="left" />
            <el-table-column label="供应商全称" prop="supplierFullName" width="150" />
            <el-table-column label="供应商编号" prop="supplierCode" width="120" sortable="custom"/>
            <el-table-column label="供应商简称" prop="supplierName" width="100" />
            <el-table-column label="业务数量" prop="businessQty" width="100" />
            <el-table-column label="品号" prop="itemCode" width="110" />
            <el-table-column label="品名" prop="itemDescription" width="150" />
            <el-table-column label="规格" prop="itemSpecification" width="150" />
            <el-table-column label="批号" prop="lotCode" width="100" />
            <el-table-column label="批号说明" prop="lotDescription" width="100" />
            <el-table-column label="件数" prop="pieces" width="100" />
            <el-table-column label="到货日期" prop="createDate" width="100" />
            <el-table-column label="创建日期" prop="arrivalDate" width="100" />
            <!-- <el-table-column label="员工姓名" prop="employeeName" width="100" />
            <el-table-column label="修改员工姓名" prop="employeeName1" width="100" /> -->
            <el-table-column label="修改日期" prop="lastModifiedDate" width="100" />
            <el-table-column label="生产批号" prop="remark" width="100" />
            <el-table-column label="操作" class-name="small-padding fixed-width" width="80" fixed="right">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-printer" @click="handleRowPrint(scope.row)"
                        v-hasPermi="['system:index:print']">生成</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.limit" @pagination="getMaterielThreeList" />
        <print-dialog v-if="printDialogVisible" :visible="printDialogVisible" :printList="printDataList" @close="onPrintDialogClose"/>
    </div>
</template>

<script>
import request from '@/utils/request'
import printDialog from './components/printDialog.vue'

export default {
    name:"materielThreeIndex"
    ,components: {
         printDialog
    }
    ,data() {
        return {
            queryParams: {
                page: 1
                ,limit: 10
                ,itemCode:''
                ,lotCode:''
                ,supplierName:''
                , docDate:''
            }
            , total: 0
            ,showSearch: true
            ,loading:false
            ,tableData: []
            ,selects:[]
            , printDialogVisible: false
            , printDataList: []
        }
    }
    ,methods: {
        getMaterielThreeList() {
            this.loading = true;
            request({
                url: '/materielThree/select'
               ,method: 'get'
               ,params: this.queryParams
            }).then(res => {
                if(res.code === 200) {
                    this.tableData = res.data.data
                    this.total = res.data.total
                }else{
                    this.$message.error(res.msg)
                }
                this.loading = false;
            })
            .catch(err => {
               console.log(err)
               this.$modal.msgError(err)
               this.loading = false;
           })
        }
        ,init(){
            this.getMaterielThreeList();
        }
        ,handleQuery(){
            this.getMaterielThreeList();
        }
        ,resetQuery(){
            this.queryParams = {
                page: 1
               ,limit: 10
               ,itemCode:''
                ,lotCode:''
                ,supplierName:''
                , docDate:''
            }
            this.getMaterielThreeList();
        }
        , handleBatchPrint() {
            if (this.printDataList.length === 0) {
                this.$modal.msgWarning("请选择需要打印的数据项。");
                return;
            }
            if (this.printDataList.length > 20) {
                this.$modal.alertWarning("一次最多可打印20条数据。");
                return;
            }
            this.printDialogVisible = true;
        }
        , handleSelectionChange(selects) {
            this.selects = [];
            this.printDataList = [];
            if (selects && selects.length !== 0) {
                this.selects = selects.map(sl => sl.assetNo);
                this.printDataList = selects.map(sl => sl);
            }
        }
        ,handleSortChange({ column, prop, order }) {
            if (order === 'ascending') {
                this.tableData.sort((a, b) => {
                    if (a[prop] < b[prop]) return -1;
                    if (a[prop] > b[prop]) return 1;
                    return 0;
                });
            } else if (order === 'descending') {
                this.tableData.sort((a, b) => {
                    if (a[prop] > b[prop]) return -1;
                    if (a[prop] < b[prop]) return 1;
                    return 0;
                });
            }
        }
        , handleRowPrint(row) {
            this.printDataList = [];
            this.printDataList.push(row);
            this.printDialogVisible = true;
        }

        , onPrintDialogClose(){
            this.printDialogVisible = false;
            this.printDataList = [];
            this.getMaterielThreeList();
        }

    }
    ,mounted() {
        this.init();
    }
}

</script>

<style scoped>

</style>
